/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Tabla;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Alex
 */
public class TipoRegistro extends DescTipo {

    private ArrayList<CampoReg> campos;

    public TipoRegistro(String nombre){
        super(tipo.REC,0,nombre);
        this.campos= new ArrayList<CampoReg>();
    }

    public ArrayList<CampoReg> getCampos() {
        return campos;
    }

    public void setCampos(ArrayList<CampoReg> campos) {
        this.campos = campos;
    }

    public tipo getTipo() {
        return t;
    }

    public void setTipo(tipo t) {
        this.t = t;
    }

    public int getTamaño() {
        return tam;
    }

    public void setTamaño(int tam) {
        this.tam = tam;
    }
    public void setNombre(String n) {
        this.nombre=n;
    }
   public boolean addCampo(CampoReg campo){
       Iterator<CampoReg> iter = campos.iterator();
       while (iter.hasNext()){
           CampoReg c= (CampoReg)iter.next();
           if (c.getId().equals(campo.getId())){
               System.err.println("El campo ya existe");
               return false;
           }
         
       }
       campos.add(campo);
       this.tam+=campo.getTipo().getTamaño();
       return true;
   }

   public CampoReg getCampo(String idCampoReg){
       CampoReg result = null;
       Iterator<CampoReg> iter = campos.iterator();
		while(iter.hasNext()){
			CampoReg c = iter.next();
			if(c.getId().equals(idCampoReg)){
				result = c;
			}
		}
		return result;
   }

    @Override
    public String getNombre() {
        return nombre;
    }
}
